package chapter7.eg3;

import java.io.IOException;
import org.msgpack.annotation.Message;
import org.msgpack.packer.Packer;
import org.msgpack.template.Template;
import org.msgpack.unpacker.Unpacker;

@Message
public class UserTemplate implements Template<User> {

  @Override
  public void write(Packer pk, User v) throws IOException {
    pk.write(v.getAge());
    pk.write(v.getName());
  }

  @Override
  public void write(Packer pk, User v, boolean required) throws IOException {
    pk.write(v.getAge());
    pk.write(v.getName());
  }

  @Override
  public User read(Unpacker u, User to) throws IOException {
    to.setAge(u.readInt());
    to.setName(u.readString());
    return to;
  }

  @Override
  public User read(Unpacker u, User to, boolean required) throws IOException {
    to.setAge(u.readInt());
    to.setName(u.readString());
    return to;
  }
}
